#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=80;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char s[maxn];
LL dp[maxn][maxn];
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL t;cin>>t;
   while(t--){
      memset(dp,0,sizeof(dp));
      cin>>(s+1);LL n=strlen(s+1);
      for(LL i=1;i<=n;i++){
          dp[i][i]=1;
          if(i!=n){
            if(s[i]==s[i+1]) dp[i][i+1]=3;
            else dp[i][i+1]=2;
          }
      }
      for(LL len=3;len<=n;len++){
          for(LL i=1;i+len-1<=n;i++){
              LL l=i;LL r=i+len-1;
              if(s[l]==s[r]){
                 dp[l][r]=dp[l][r]+dp[l+1][r]+dp[l][r-1]+1;
              }
              else{
                 dp[l][r]=dp[l][r]+dp[l+1][r]+dp[l][r-1]-dp[l+1][r-1];
              }
          }
      }
      cout<<dp[1][n]<<"\n";
   }
   return 0;
}
